package com.app.bimo.module_accounts.mvp.ui.view;


import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.app.bimo.commonbusiness.util.DataUtil;
import com.app.bimo.commonbusiness.util.UiUtil;
import com.app.bimo.commonbusiness.view.recyclerview.RecycleAdapterImpl;
import com.app.bimo.commonbusiness.view.recyclerview.RecyclerViewHolder;
import com.app.bimo.module_accounts.R;
import com.app.bimo.module_accounts.mvp.model.entiy.TagData;

import java.util.List;


public class UserPreferTagAdapter extends RecycleAdapterImpl<TagData> {
    private String searchString = "";
    private TagChooseClick tagChooseClick;

    public UserPreferTagAdapter(List<TagData> list, Context context) {
        super(list, context);
    }


    @Override
    public int getCount() {
        return list.size();
    }

    public void setSearchString(String searchString) {
        this.searchString = searchString;
    }

    @Override
    public int getViewId(int type) {
        return R.layout.adapter_prefer_tag;
    }

    public void setTagChooseClick(TagChooseClick tagChooseClick) {
        this.tagChooseClick = tagChooseClick;
    }

    @Override
    public RecyclerViewHolder getHold(int id) {
        return new Hold(id, context);
    }

    @Override
    public void initView(RecyclerViewHolder thold, int position) {
        Hold hold = (Hold) thold;
        TagData data = getItem(position);
        if (DataUtil.isEmpty(searchString)) {
            hold.tag.setText(data.getTagName());
        } else {
            hold.tag.setText(UiUtil.matchSearchText(context.getResources().getColor(R.color.blue_38a6fe), data.getTagName(), searchString));
        }
        hold.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (tagChooseClick != null) {
                    tagChooseClick.click(data);
                }
            }
        });
    }

    class Hold extends RecyclerViewHolder {

        public Hold(int arg0, Context context) {
            super(arg0, context);
        }

        TextView tag;
        TextView chooseBtn;
    }


}
